Release 10.1A: OpenEdge Development:
Progress 4GL Reference
CASE statement
Provides a multi-branch decision based on the value of a single expression.
Syntax
expressionThe expression that determines which branch of code to execute. The
expressionparameter can be any valid Progress expression. It can include comparisons, logical operations, and parentheses.WHENvalue[ OR WHENvalue] . . . THENEach
valueis an expression that evaluates to a possible value forexpression. Ifvaluematches the current value ofexpression, then the associated block or statement executes.OTHERWISEIntroduces a block or statement to execute when the value of
expressiondoes not match anyvaluein any of the WHEN clauses.blockA DO, FOR EACH, or REPEAT block. If you do not use a block, then you can only use a single statement for the WHEN or OTHERWISE clause.
statementA single 4GL statement. If you want to use more than one statement, you must enclose them in a DO, FOR EACH, or REPEAT block.
END [ CASE ]Indicates the end of the CASE statement. You can include the CASE keyword here to improve readability; it has no effect on the code.
ExampleThe following fragment shows a simple example of a CASE statement:
Notes
- Each
valuemust have the same data type asexpression. If the data types do not match, the compiler reports an error.- You can specify any number of WHEN clauses within the CASE statement.
- You can specify only one OTHERWISE clause for a CASE statement. If you use the OTHERWISE clause, it must be the last branch in the statement.
- When a CASE statement is executed, Progress evaluates
expressionand evaluates eachvaluefor each branch in order of occurrence until it finds the firstvaluethat satisfies the condition. At that point Progress executes that branch and does not evaluate any othervaluefor that branch or any other branches. If no matchingvalueis found, then the OTHERWISE branch is executed, if given. If the OTHERWISE branch is not given and no matchingvalueis found, then no branch of the CASE statement is executed and execution continues with the statement after the CASE statement.- After a branch of the CASE statement is executed, Progress leaves the CASE statement and execution continues with the statement following the CASE statement.
- If a LEAVE statement is executed within any branch of a CASE statement, Progress leaves the closest block (other than a DO block) that encloses the CASE statement.
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |